/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ClockedTimesDialog.java
 *
 * Created on 15-Mar-2011, 21:33:40
 */

package TimeRecording.forms;

import TimeRecording.TimeRecordingView;
import TimeRecording.business.DaisyChainUtilities;
import TimeRecording.business.DateRange;
import TimeRecording.business.IntegerTimeRange;
import TimeRecording.business.IntegerTimeRangeArrayList;
import TimeRecording.forms.renderers.CentredCellRenderer;
import TimeRecording.forms.renderers.HourlySliceRenderer;
import TimeRecording.forms.renderers.TableRowHeaderRenderer;
import TimeRecording.tables.ClockedPeriod;
import TimeRecording.tables.Employee;
import TimeRecording.widgets.EmployeeComboBox;
import java.util.Date;
import java.util.Formatter;
import java.util.GregorianCalendar;
import java.util.List;
import javax.persistence.EntityManager;
import javax.swing.JList;
import javax.swing.border.EmptyBorder;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumnModel;
import org.jdesktop.application.Action;

/**
 *
 * @author david
 */
public class ClockedTimesDialog extends javax.swing.JDialog {

    // <editor-fold defaultstate="collapsed" desc="Main [Graphical] Table Model">
    private class ClockedTimeTableModel extends DefaultTableModel {

        private final String[] HEADINGS = new String[] {
                "Monday", "Tuesday", "Wednesday", "Thursday",
                "Friday", "Saturday", "Sunday"};

        private IntegerTimeRangeArrayList[] periods;

        public ClockedTimeTableModel() {

            periods = new IntegerTimeRangeArrayList[7];
            for (int index = 0; index < 7; index++) {
                periods[index] = new IntegerTimeRangeArrayList();
            }
        }

        @Override
        public int getColumnCount() {
            return 7;
        }

        @Override
        public int getRowCount() {
            return 24;
        }

        @Override
        public String getColumnName(int column) {
            return HEADINGS[column];
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }

        @Override
        public Object getValueAt(int row, int column) {

            IntegerTimeRange crop = new IntegerTimeRange(row * 60, (row + 1) * 60);
            IntegerTimeRangeArrayList value = periods[column].crop(crop);
            value.normalise(crop.getMinutesFrom());
            return value;
        }

        public int getTotal(int column) {
            int total = 0;
            IntegerTimeRangeArrayList values = periods[column];
            for (IntegerTimeRange value : values) {
                total += value.getMinutes();
            }
            return total;
        }

        public void clearPeriods() {
            for (int index = 0; index < 7; index++) {
                periods[index].clear();
            }
        }

        public void addPeriod(int day, int minutesFrom, int minutesTo) {
            periods[day].add(new IntegerTimeRange(minutesFrom, minutesTo));
        }
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Summary Table Model">
    private class SummaryTableModel extends DefaultTableModel {

        private final String[] HEADINGS = new String[] {
                "Monday", "Tuesday", "Wednesday", "Thursday",
                "Friday", "Saturday", "Sunday"};

        private ClockedTimeTableModel mainModel;

        public SummaryTableModel(ClockedTimeTableModel mainModel) {
            this.mainModel = mainModel;
        }

        @Override
        public int getColumnCount() {
            return 7;
        }

        @Override
        public int getRowCount() {
            return 3;
        }

        @Override
        public String getColumnName(int column) {
            return HEADINGS[column];
        }

        @Override
        public boolean isCellEditable(int row, int column) {
            return false;
        }

        @Override
        public Object getValueAt(int row, int column) {
            int totalMinutes = mainModel.getTotal(column);
            int hours = totalMinutes / 60;
            int minutes = totalMinutes - hours * 60;
            return new Formatter().format("%1$02d:%2$02d",
                    hours, minutes).toString();
        }
    }
    // </editor-fold>

    private TimeRecordingView myParent;
    private EntityManager entityManager;
    private ClockedTimeTableModel tableModel = new ClockedTimeTableModel();
    private SummaryTableModel summaryModel = new SummaryTableModel(tableModel);
    private HourlySliceRenderer sliceRenderer = new HourlySliceRenderer();

    private Employee selectedEmployee;
    private Date startOfWeek;
    private Date endOfWeek;

    public Employee getSelectedEmployee() {
        return selectedEmployee;
    }

    public void setSelectedEmployee(Employee selectedEmployee) {
        Employee oldSelectedEmployee = this.selectedEmployee;
        this.selectedEmployee = selectedEmployee;
        firePropertyChange("selectedEmployee", oldSelectedEmployee, selectedEmployee);
    }

    public Date getStartOfWeek() {
        return startOfWeek;
    }

    public void setStartOfWeek(Date startOfWeek) {
        Date oldStartOfWeek = this.startOfWeek;
        this.startOfWeek = startOfWeek;
        firePropertyChange("startOfWeek", oldStartOfWeek, startOfWeek);
    }

    public Date getEndOfWeek() {
        return endOfWeek;
    }

    public void setEndOfWeek(Date endOfWeek) {
        Date oldEndOfWeek = this.endOfWeek;
        this.endOfWeek = endOfWeek;
        firePropertyChange("endOfWeek", oldEndOfWeek, endOfWeek);
    }

    /** Creates new form ClockedTimesDialog */
    public ClockedTimesDialog(TimeRecordingView parent,
            EntityManager entityManager) {

        super(parent.getFrame(), false);

        myParent = parent;
        this.entityManager = entityManager;

        initComponents();

        // Set up row headers on the main table

        JList mainTableRowHeader = new JList(new String[] {
                "00:00", "01:00", "02:00", "03:00", "04:00", "05:00",
                "06:00", "07:00", "08:00", "09:00", "10:00", "11:00",
                "12:00", "13:00", "14:00", "15:00", "16:00", "17:00",
                "18:00", "19:00", "20:00", "21:00", "22:00", "23:00"});

        mainTableRowHeader.setFixedCellWidth(100);
        mainTableRowHeader.setFixedCellHeight(
                clockedTimeTable.getRowHeight());
        mainTableRowHeader.setCellRenderer(
                new TableRowHeaderRenderer(clockedTimeTable));
        mainTableRowHeader.setBackground(
                clockedTimeTable.getTableHeader().getBackground());

        clockedTimePanel.setRowHeaderView(mainTableRowHeader);

        clockedTimeTable.setModel(tableModel);
        for (int index = 0; index < 7; index++) {
            clockedTimeTable.getColumnModel().getColumn(index)
                    .setCellRenderer(sliceRenderer);
        }

        clockedTimeTable.scrollRectToVisible(
                clockedTimeTable.getCellRect(8, 0, true));

        // Set up row headers on the "totals" table

        JList summaryTableRowHeader = new JList(new String[] {
                "Totals", "Flexi Balance", "Weekly Balance"});

        summaryTableRowHeader.setFixedCellWidth(100);
        summaryTableRowHeader.setFixedCellHeight(
                summaryTable.getRowHeight());
        summaryTableRowHeader.setCellRenderer(
                new TableRowHeaderRenderer(summaryTable));
        summaryTableRowHeader.setBackground(
                summaryTable.getTableHeader().getBackground());

        CentredCellRenderer summaryRenderer = new CentredCellRenderer();

        summaryPanel.setRowHeaderView(summaryTableRowHeader);
        summaryTable.setModel(summaryModel);
        summaryPanel.setBorder(new EmptyBorder(0, 1, 0, clockedTimePanel.
                getVerticalScrollBar().getPreferredSize().width));
        summaryTable.setTableHeader(null);

        TableColumnModel columnModel = summaryTable.getColumnModel();
        for (int index = 0; index < 7; index++) {
            columnModel.getColumn(index).setCellRenderer(summaryRenderer);
        }

        setStartOfWeek(DaisyChainUtilities.firstDayOfWeek(
                (GregorianCalendar)null).getTime());
        setEndOfWeek(DaisyChainUtilities.lastDayOfWeek(
                (GregorianCalendar)null).getTime());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        navigatorPanel = new javax.swing.JPanel();
        employeeLabel = new javax.swing.JLabel();
        prevEmployeeButton = new javax.swing.JButton();
        employeeComboBox = new EmployeeComboBox(entityManager);
        nextEmployeeButton = new javax.swing.JButton();
        weekLabel = new javax.swing.JLabel();
        prevWeekButton = new javax.swing.JButton();
        startDate = new javax.swing.JFormattedTextField();
        endDate = new javax.swing.JFormattedTextField();
        nextWeekButton = new javax.swing.JButton();
        tablesPanel = new javax.swing.JPanel();
        clockedTimePanel = new javax.swing.JScrollPane();
        clockedTimeTable = new javax.swing.JTable();
        summaryPanel = new javax.swing.JScrollPane();
        summaryTable = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(TimeRecording.TimeRecordingApp.class).getContext().getResourceMap(ClockedTimesDialog.class);
        setTitle(resourceMap.getString("Form.title")); // NOI18N
        setName("Form"); // NOI18N
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                formWindowClosing(evt);
            }
        });
        getContentPane().setLayout(new java.awt.GridBagLayout());

        navigatorPanel.setName("navigatorPanel"); // NOI18N
        navigatorPanel.setLayout(new java.awt.GridBagLayout());

        employeeLabel.setText(resourceMap.getString("employeeLabel.text")); // NOI18N
        employeeLabel.setName("employeeLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 4);
        navigatorPanel.add(employeeLabel, gridBagConstraints);

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(TimeRecording.TimeRecordingApp.class).getContext().getActionMap(ClockedTimesDialog.class, this);
        prevEmployeeButton.setAction(actionMap.get("prevEmployeeClicked")); // NOI18N
        prevEmployeeButton.setText(resourceMap.getString("prevEmployeeButton.text")); // NOI18N
        prevEmployeeButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        prevEmployeeButton.setName("prevEmployeeButton"); // NOI18N
        prevEmployeeButton.setPreferredSize(new java.awt.Dimension(32, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        navigatorPanel.add(prevEmployeeButton, gridBagConstraints);

        employeeComboBox.setName("employeeComboBox"); // NOI18N
        employeeComboBox.setPreferredSize(new java.awt.Dimension(200, 20));

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${selectedEmployee}"), employeeComboBox, org.jdesktop.beansbinding.BeanProperty.create("selectedItem"));
        bindingGroup.addBinding(binding);

        employeeComboBox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                employeeSelected(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        navigatorPanel.add(employeeComboBox, gridBagConstraints);

        nextEmployeeButton.setAction(actionMap.get("nextEmployeeClicked")); // NOI18N
        nextEmployeeButton.setText(resourceMap.getString("nextEmployeeButton.text")); // NOI18N
        nextEmployeeButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        nextEmployeeButton.setName("nextEmployeeButton"); // NOI18N
        nextEmployeeButton.setPreferredSize(new java.awt.Dimension(32, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 8);
        navigatorPanel.add(nextEmployeeButton, gridBagConstraints);

        weekLabel.setText(resourceMap.getString("weekLabel.text")); // NOI18N
        weekLabel.setName("weekLabel"); // NOI18N
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.insets = new java.awt.Insets(4, 8, 4, 4);
        navigatorPanel.add(weekLabel, gridBagConstraints);

        prevWeekButton.setAction(actionMap.get("prevWeekClicked")); // NOI18N
        prevWeekButton.setText(resourceMap.getString("prevWeekButton.text")); // NOI18N
        prevWeekButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        prevWeekButton.setName("prevWeekButton"); // NOI18N
        prevWeekButton.setPreferredSize(new java.awt.Dimension(32, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        navigatorPanel.add(prevWeekButton, gridBagConstraints);

        startDate.setEditable(false);
        startDate.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
        startDate.setName("startDate"); // NOI18N
        startDate.setPreferredSize(new java.awt.Dimension(90, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${startOfWeek}"), startDate, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        navigatorPanel.add(startDate, gridBagConstraints);

        endDate.setEditable(false);
        endDate.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
        endDate.setName("endDate"); // NOI18N
        endDate.setPreferredSize(new java.awt.Dimension(90, 20));

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, this, org.jdesktop.beansbinding.ELProperty.create("${endOfWeek}"), endDate, org.jdesktop.beansbinding.BeanProperty.create("value"));
        bindingGroup.addBinding(binding);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 3;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        navigatorPanel.add(endDate, gridBagConstraints);

        nextWeekButton.setAction(actionMap.get("nextWeekClicked")); // NOI18N
        nextWeekButton.setText(resourceMap.getString("nextWeekButton.text")); // NOI18N
        nextWeekButton.setMargin(new java.awt.Insets(2, 2, 2, 2));
        nextWeekButton.setName("nextWeekButton"); // NOI18N
        nextWeekButton.setPreferredSize(new java.awt.Dimension(32, 20));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 4;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 8);
        navigatorPanel.add(nextWeekButton, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        getContentPane().add(navigatorPanel, gridBagConstraints);

        tablesPanel.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEmptyBorder(4, 4, 4, 4), javax.swing.BorderFactory.createEtchedBorder()));
        tablesPanel.setName("tablesPanel"); // NOI18N
        tablesPanel.setLayout(new java.awt.GridBagLayout());

        clockedTimePanel.setBorder(null);
        clockedTimePanel.setName("clockedTimePanel"); // NOI18N

        clockedTimeTable.setName("clockedTimeTable"); // NOI18N
        clockedTimeTable.setRowHeight(30);
        clockedTimePanel.setViewportView(clockedTimeTable);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 4.0;
        tablesPanel.add(clockedTimePanel, gridBagConstraints);

        summaryPanel.setMinimumSize(new java.awt.Dimension(23, 64));
        summaryPanel.setName("summaryPanel"); // NOI18N

        summaryTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        summaryTable.setName("summaryTable"); // NOI18N
        summaryPanel.setViewportView(summaryTable);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        tablesPanel.add(summaryPanel, gridBagConstraints);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 1.0;
        getContentPane().add(tablesPanel, gridBagConstraints);

        bindingGroup.bind();

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-560)/2, (screenSize.height-641)/2, 560, 641);
    }// </editor-fold>//GEN-END:initComponents

    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
        myParent.hideClockedTimesDialog();
    }//GEN-LAST:event_formWindowClosing

    @Action
    public void prevWeekClicked() {

        GregorianCalendar cal = new GregorianCalendar();
        
        cal.setTime(getStartOfWeek());
        cal.add(GregorianCalendar.WEEK_OF_YEAR, -1);
        setStartOfWeek(cal.getTime());

        cal.setTime(getEndOfWeek());
        cal.add(GregorianCalendar.WEEK_OF_YEAR, -1);
        setEndOfWeek(cal.getTime());

        populateTable();
    }

    @Action
    public void nextWeekClicked() {

        GregorianCalendar cal = new GregorianCalendar();

        cal.setTime(getStartOfWeek());
        cal.add(GregorianCalendar.WEEK_OF_YEAR, 1);
        setStartOfWeek(cal.getTime());

        cal.setTime(getEndOfWeek());
        cal.add(GregorianCalendar.WEEK_OF_YEAR, 1);
        setEndOfWeek(cal.getTime());

        populateTable();
    }

    private void employeeSelected(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_employeeSelected
        populateTable();
    }//GEN-LAST:event_employeeSelected

    @Action
    public void prevEmployeeClicked() {
        int index = employeeComboBox.getSelectedIndex() - 1;
        if (index >= 0) {
            employeeComboBox.setSelectedIndex(index);
            populateTable();
        }
    }

    @Action
    public void nextEmployeeClicked() {
        int index = employeeComboBox.getSelectedIndex() + 1;
        if (index < employeeComboBox.getItemCount()) {
            employeeComboBox.setSelectedIndex(index);
            populateTable();
        }
    }

    private void populateTable() {

        if (selectedEmployee == null) {
            return;
        }

        // Get the date range right up to midnight of the last day

        Date start = (Date)startDate.getValue();
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime((Date)endDate.getValue());
        cal.set(GregorianCalendar.HOUR_OF_DAY, 23);
        cal.set(GregorianCalendar.MINUTE, 59);
        cal.set(GregorianCalendar.SECOND, 59);
        cal.set(GregorianCalendar.MILLISECOND, 999);
        Date end = cal.getTime();

        DateRange dateRange = new DateRange(start, end);
        // Get the entries
        List<ClockedPeriod> clockedEntries = ClockedPeriod.
                getClockedPeriodsForEmployeeAndPeriod(
                        entityManager, selectedEmployee, dateRange);

        // Put the entries into the table model
        tableModel.clearPeriods();
        for (ClockedPeriod period : clockedEntries) {

            cal.setTime(period.getClockedPeriodPK().getClockedIn());
            int day = cal.get(GregorianCalendar.DAY_OF_WEEK) - 1;

            int minutesFrom =
                    cal.get(GregorianCalendar.HOUR_OF_DAY) * 60 +
                    cal.get(GregorianCalendar.MINUTE);

            // If the entry is not clocked out then assume the end time is NOW.
            // We should never get clocked entries open over midnight but even
            // if we do then the minute calcs work off hours and minutes only.

            if (period.getClockedOut() != null) {
                cal.setTime(period.getClockedOut());
            } else {
                cal.setTime(new Date());
            }

            int minutesTo =
                    cal.get(GregorianCalendar.HOUR_OF_DAY) * 60 +
                    cal.get(GregorianCalendar.MINUTE);

            if (minutesTo < minutesFrom) {
                minutesTo = minutesFrom + 60;
                if (minutesTo > 24 * 60 - 1) {
                    minutesTo = 24 * 60 - 1;
                }
            }

            tableModel.addPeriod(day, minutesFrom, minutesTo);
        }

        // Update the table
        tableModel.fireTableDataChanged();
        summaryModel.fireTableDataChanged();
    }


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane clockedTimePanel;
    private javax.swing.JTable clockedTimeTable;
    private javax.swing.JComboBox employeeComboBox;
    private javax.swing.JLabel employeeLabel;
    private javax.swing.JFormattedTextField endDate;
    private javax.swing.JPanel navigatorPanel;
    private javax.swing.JButton nextEmployeeButton;
    private javax.swing.JButton nextWeekButton;
    private javax.swing.JButton prevEmployeeButton;
    private javax.swing.JButton prevWeekButton;
    private javax.swing.JFormattedTextField startDate;
    private javax.swing.JScrollPane summaryPanel;
    private javax.swing.JTable summaryTable;
    private javax.swing.JPanel tablesPanel;
    private javax.swing.JLabel weekLabel;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
